package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BkComment;
import com.ruoyi.system.service.IBkCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文章评论Controller
 * 
 * @author ruoyi
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/bk/comment")
public class BkCommentController extends BaseController
{
    @Autowired
    private IBkCommentService bkCommentService;

    /**
     * 查询文章评论列表
     */
//    @PreAuthorize("@ss.hasPermi('bk:comment:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(BkComment bkComment)
    {
        startPage();
        List<BkComment> list = bkCommentService.selectBkCommentList(bkComment);
        return getDataTable(list);
    }

    /**
     * 导出文章评论列表
     */
    @PreAuthorize("@ss.hasPermi('bk:comment:export')")
    @Log(title = "文章评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BkComment bkComment)
    {
        List<BkComment> list = bkCommentService.selectBkCommentList(bkComment);
        ExcelUtil<BkComment> util = new ExcelUtil<BkComment>(BkComment.class);
        util.exportExcel(response, list, "文章评论数据");
    }

    /**
     * 获取文章评论详细信息
     */
//    @PreAuthorize("@ss.hasPermi('bk:comment:query')")
    @Anonymous
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
    {
        return success(bkCommentService.selectBkCommentByCommentId(commentId));
    }

    /**
     * 新增文章评论
     */
//    @PreAuthorize("@ss.hasPermi('bk:comment:add')")
    @Anonymous
//    @Log(title = "文章评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BkComment bkComment)
    {
        return toAjax(bkCommentService.insertBkComment(bkComment));
    }

    /**
     * 修改文章评论
     */
    @PreAuthorize("@ss.hasPermi('bk:comment:edit')")
    @Log(title = "文章评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BkComment bkComment)
    {
        return toAjax(bkCommentService.updateBkComment(bkComment));
    }

    /**
     * 删除文章评论
     */
    @PreAuthorize("@ss.hasPermi('bk:comment:remove')")
    @Log(title = "文章评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(bkCommentService.deleteBkCommentByCommentIds(commentIds));
    }
    /**
     * 邮件服务接口
     */
    public interface EmailService {
        /**
         * 发送HTML格式邮件
         *
         * @param to 收件人
         * @param subject 主题
         * @param content HTML内容
         */
        void sendHtmlMail(String to, String subject, String content);
    }
}
